<div class="tabbable" id="svn-administration">
    {{> admin/section_presenter }}

    <div class="tab-content" id="notifications">
        <h3>{{ notification_subtitle }}</h3>
        <p>{{ comment }}</p>

        <form action="/plugins/svn/?group_id={{ project_id }}&repo_id={{ repository_id }}&action=save-mail-header" method="post">
            <input type="hidden" name="group_id" value="{{ project_id }}">
            <input type="hidden" name="repo_id" value="{{ repository_id }}">
            {{{ csrf_input }}}

            <label>{{ label_subject_header }}</label>
            <div class="input-append">
                <input type="text" name="form_mailing_header" value="{{ subject_header }}">
                <button type="submit" name="submit" class="btn"><i class="icon-save"></i> {{ save_subject }}</button>
            </div>
        </form>

        <form id="svn-admin-notifications-form" action="/plugins/svn/?group_id={{ project_id }}&repo_id={{ repository_id }}&action=update-mailing-lists" method="post">
            <h4>{{ label_notification_aviable }}</h4>
            <table class="table">
                <thead>
                <tr>
                    <th>{{ monitored_path }}</th>
                    <th class="svn-notifications-form-emails-column">{{ notified_mails }}</th>
                    <th></th>
                </tr>
                </thead>
                <tbody>
                {{# has_notifications }}
                    {{# notifications }}
                        {{# has_notified }}
                            <tr data-target-input-id="edit_email_{{ notification_id }}">
                                <td>
                                    <div class="svn-notifications-checkbox-cell-read">
                                        <div>{{ path }}</div>
                                    </div>
                                    <div class="svn-notifications-checkbox-cell-write svn-notifications-checkbox-cell-hidden">
                                        {{# path }}
                                            <input type="text"
                                                   class="svn-notification-edit-input edit-path input-path"
                                                   name="notification_update[{{ notification_id }}][path]"
                                                   value="{{ path }}"
                                                   data-notification-id="{{ notification_id }}"
                                                   disabled
                                            />
                                        {{/ path }}
                                    </div>
                                </td>
                                <td>
                                    <div class="svn-notifications-checkbox-cell-read">
                                        <div class="svn-notification-email-list">
                                            {{# ugroups_to_be_notified }}
                                                <span class="svn-notification-email-list-entry">
                                                <i class="icon-group svn-notification-email-list-group-icon"></i>
                                                    {{ label }}<span class="svn-notification-email-list-separator">, </span>
                                                </span>
                                            {{/ ugroups_to_be_notified }}
                                            {{# users_to_be_notified }}
                                                <span class="svn-notification-email-list-entry">
                                                <div class="avatar svn-notification-user-avatar">
                                                    {{# has_avatar }}<img src="{{ avatar_url }}" />{{/ has_avatar }}
                                                </div>
                                                    {{ label }}<span class="svn-notification-email-list-separator">, </span>
                                            </span>
                                            {{/ users_to_be_notified }}
                                            {{# emails_to_be_notified }}
                                                <span class="svn-notification-email-list-entry">
                                                {{ . }}<span class="svn-notification-email-list-separator">, </span>
                                            </span>
                                            {{/ emails_to_be_notified }}
                                        </div>
                                    </div>
                                    <div class="svn-notifications-checkbox-cell-write svn-notifications-checkbox-cell-hidden">
                                        {{# has_notified }}
                                            <input type="text"
                                                   id="edit_email_{{ notification_id }}"
                                                   class="edit_email autocompleter-users-and-ugroups-input"
                                                   name="notification_update[{{ notification_id }}][emails]"
                                                   data-project-id="{{ project_id }}"
                                                   data-emails="{{ emails_to_be_notified_json }}"
                                                   data-users="{{ users_to_be_notified_json }}"
                                                   data-ugroups="{{ ugroups_to_be_notified_json }}"
                                                   disabled
                                            />
                                        {{/ has_notified }}
                                    </div>
                                </td>
                                <td class="svn-notification-form-actions">
                                    <div class="svn-notifications-checkbox-cell-write svn-notifications-checkbox-cell-hidden">
                                        <button type="submit"
                                                id="svn-notification-save-{{ notification_id }}"
                                                name="save-mailing-lists"
                                                value="1"
                                                class="btn btn-primary svn-notification-save"
                                                data-toggle="popover"
                                                data-trigger="manual"
                                                data-placement="bottom"
                                                data-html="true"
                                                data-popover-id="svn-notification-cannot-save-{{ notification_id }}-popover"
                                        >
                                            {{ save }}
                                        </button>
                                        <div id="svn-notification-cannot-save-{{ notification_id }}-popover"
                                             data-title="{{ cannot_save_title }}"
                                             class="svn-notification-cannot-save-popover">
                                            <p>{{ cannot_save_desc }}</p>
                                        </div>
                                        <button type="button" name="submit" class="btn svn-notification-edit-hide">{{ cancel }}</button>
                                    </div>
                                    <div class="svn-notifications-checkbox-cell-read">
                                        <a href="javascript:;" class="svn-notification-edit-show svn-notification-edit">
                                            <i class="icon-pencil"></i>
                                            {{ edit }}
                                        </a>
                                        <a href="javascript:;"
                                           class="svn-notification-delete"
                                           data-toggle="popover"
                                           data-trigger="click"
                                           data-placement="left"
                                           data-html="true"
                                           data-popover-id="svn-notification-delete-{{ notification_id }}-popover"
                                        >
                                            <i class="icon-trash"></i>
                                            {{ delete }}
                                        </a>
                                        <div id="svn-notification-delete-{{ notification_id }}-popover"
                                             data-title="{{ remove_notification_title }}"
                                             class="svn-notification-delete-popover">
                                            <p>{{ remove_notification_desc }}</p>

                                            <div class="svn-notification-delete-popover-actions">
                                                <input type="hidden" name="notification_remove_id" value="{{ notification_id }}">
                                                <button type="button" class="btn btn-small btn-default dismiss-popover">{{ cancel }}</button>
                                                <button type="submit"
                                                        name="delete-mailing-lists"
                                                        value="1"
                                                        class="btn btn-small btn-danger"
                                                >{{ remove_notification_confirm }}</button>
                                            </div>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                        {{/ has_notified }}
                    {{/ notifications }}
                {{/ has_notifications }}
                {{^ has_notifications }}
                    <tr>
                        <td class="table-cell-empty" colspan="3">{{ no_notifications_message }}</td>
                    </tr>
                {{/ has_notifications }}
                <tr id="svn-notifications-row-add" class="svn-notifications-row-add-hidden">
                    <td class="notification-path">
                        <input type="text"
                               id="add_path"
                               name="notification_add[path]"
                               class="input-path"
                               placeholder="{{ label_path }}"
                        />
                    </td>
                    <td>
                        <input type="text"
                               id="add_email"
                               name="notification_add[emails]"
                               class="autocompleter-users-and-ugroups-input"
                               placeholder="{{ new_notification_placeholder }}"
                               data-project-id="{{ project_id }}"
                               multiple
                        />
                    </td>
                    <td class="svn-notification-edit">
                        <button type="submit"
                                id="svn-notification-save-adding-notification"
                                name="save-mailing-lists"
                                value="1"
                                class="btn btn-primary svn-notification-save"
                                data-toggle="popover"
                                data-trigger="manual"
                                data-placement="bottom"
                                data-html="true"
                                data-popover-id="svn-notification-cannot-save-popover"
                        >
                            {{ save }}
                        </button>
                        <div id="svn-notification-cannot-save-popover"
                             data-title="{{ cannot_save_title }}"
                             class="svn-notification-cannot-save-popover">
                            <p>{{ cannot_save_desc }}</p>
                        </div>
                        <button type="button" name="submit" class="btn svn-notification-edit-hide">{{ cancel }}</button>
                    </td>
                </tr>
                </tbody>
            </table>
            <button type="button" class="btn" id="svn-notifications-add">
                <i class="icon-plus"></i>
                {{ add_notification }}
            </button>

            <input type="hidden" name="group_id" value="{{ project_id }}">
            <input type="hidden" name="repo_id" value="{{ repository_id }}">
            {{{ csrf_input }}}
        </form>
        <div id="svn-notification-cannot-save-popover-container"></div>
    </div>
</div>
